/**
 *  *2010-5-15 下午01:09:50  add 
 */
package com.base.myproject.client.HR.Self;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.LasyObejct;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.ui.BaseFormPanel;
import com.base.myproject.client.ui.BaseGrid;
import com.base.myproject.client.ui.BaseGridPanel;
import com.base.myproject.client.ui.celleditor.BaseComboBoxForm;
import com.base.myproject.client.ui.celleditor.BaseComboBoxX;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.ListView;
import com.extjs.gxt.ui.client.widget.TabItem;
import com.extjs.gxt.ui.client.widget.TabPanel;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author Administrator 2010-5-15 javazgw@gmail.com
 */
public class SelfBcode_HR extends LayoutContainer implements LasyObejct {

	BaseStore<BusiObject> mainstore = null;

	BaseFormPanel form = null;
	static  String hr_bcode="";//类变量  用来保存雇员编号  其他页面会用到处理问题
	BaseComboBoxForm<BaseModelData> C_num26 ;
	BaseComboBoxForm<BaseModelData> C_num27;
	BaseComboBoxX C_num30 ;//工资策略
	NumberField  C_num31;//工资
	BaseComboBoxForm<BaseModelData> C_dep ;//上级部门  
	TextField<String> C_num25;//识别码
	BaseComboBoxForm<BaseModelData> C_num32 ;//个税策略
	TextField<String> C_num2;//人员编码
	
	ArrayList<BaseStore> refresh_list = new ArrayList<BaseStore>() ;
	
	BaseComboBoxX bc16;
	BaseComboBoxX C_num17;
	BaseComboBoxX C_num18;
	
	public SelfBcode_HR(BaseStore<BusiObject> mainstore) {
		this.mainstore = mainstore;
		init();

	}
	public SelfBcode_HR() {
	}


	void init() {
		initwidget();

	}

	Widget initwidget() {
		FieldSet fs1 = new FieldSet();
		//fs1.setStyleName("firldset_css1");
		fs1.add(createForm());
		fs1.setHeading("基本信息");
		TabPanel tabpanel = new TabPanel();
		tabpanel.setHeight(190);
		tabpanel.setWidth(765);
		TabItem t1 = new TabItem();
		t1.setText("地址资料");
		t1.add(createGrid());
		t1.setScrollMode(Scroll.AUTO);
		
		TabItem t2 = new TabItem();
		t2.setText("证件资料");
		t2.add(create_card_Grid());
		t2.setScrollMode(Scroll.AUTO);
		tabpanel.add(t2);
		tabpanel.add(t1);
		
		
		VerticalPanel v = new VerticalPanel();
		v.setSpacing(2);
		v.add(fs1);
		v.add(tabpanel);
		//v.setHeight(420);
		this.add(v);
		return null;
	}
	TextField<String> C_num3 = new TextField<String>();
	TextField<String> C_num4 = new TextField<String>();
	TextField<String> C_num28 = new TextField<String>();
	BaseFormPanel createForm() {
		BaseFormPanel form = new BaseFormPanel(mainstore);
		form.setBodyBorder(false);
		form.setStyleName("form_css2");
		form.setPadding(6);
		TableLayout tl = new TableLayout(8);

		TableData td = new TableData();
		td.setRowspan(1);
		td.setHorizontalAlign(HorizontalAlignment.LEFT);
		td.setVerticalAlign(VerticalAlignment.TOP);
		td.setPadding(2);
		
		TableData td2 = new TableData();
		td2.setRowspan(7);
		td2.setHorizontalAlign(HorizontalAlignment.RIGHT);
		td2.setVerticalAlign(VerticalAlignment.TOP);
		td2.setPadding(2);
		td2.setColspan(2);
		
		form.setLayout(tl);
		form.setHeaderVisible(false);
		
		form.add(new Label("姓名:"), td);
		C_num28.setReadOnly(true);
		C_num28.setName("bname");
		form.add(C_num28, td);
		
		form.add(new Label("性别:"), td);
		TextField<String> C_numsex = new TextField<String>();
		C_numsex.setReadOnly(true);
		C_numsex.setName("sex");
		form.add(C_numsex, td);
		
		form.add(new Label("出生日期:"), td);
		DateField C_data45  = new DateField(); 
		C_data45.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-M-d"));
		C_data45.setReadOnly(true);
		C_data45.setWidth(127);
		C_data45.setName("bird");
		form.add(C_data45, td);
		
		//图片显示
		form.add(CreateView(), td2);
		
		form.add(new Label("人员编码:"), td);
		C_num2 = new TextField<String>();
		C_num2.setReadOnly(true);
		C_num2.setName("bcode");
		form.add(C_num2, td);
		
		form.add(new Label("简码:"), td);
		TextField<String> C_num24 = new TextField<String>();
		C_num24.setReadOnly(true);
		C_num24.setName("shortcode");
		form.add(C_num24, td);
		
		form.add(new Label("婚姻状况:"), td);
		TextField<String> C_num14 = new TextField<String>();
		C_num14.setReadOnly(true);
		C_num14.setName("hr_Marital_status");
		form.add(C_num14, td);
		
		form.add(new Label("户籍省份:"), td);
		TextField<String> bc16 = new TextField<String>();
		bc16.setReadOnly(true);
		bc16.setName("hr_Census_Province");
		form.add(bc16, td);
		
		form.add(new Label("户籍市:"), td);
		TextField<String> C_num17 = new TextField<String>();
		C_num17.setReadOnly(true);
		C_num17.setName("hr_Census_city");
		form.add(C_num17, td);
		
		form.add(new Label("户籍区:"), td);
		TextField<String> C_num18 = new TextField<String>();
		C_num18.setName("hr_Census_area");
		C_num18.setReadOnly(true);
		form.add(C_num18, td);
		
		form.add(new Label("姓:"), td);	
		C_num3.setReadOnly(true);
		C_num3.setName("hr_firstname_zh");
		form.add(C_num3, td);
		
		form.add(new Label("名:"), td);
		C_num4.setReadOnly(true);
		C_num4.setName("hr_lastname_zh");
		form.add(C_num4, td);
		
		form.add(new Label("国籍:"), td);
		TextField<String> C_num13 = new TextField<String>();
		C_num13.setReadOnly(true);
		C_num13.setName("hr_nationality");
		form.add(C_num13, td);
		
		form.add(new Label("firstname:"), td);
		TextField<String> C_num5 = new TextField<String>();
		C_num5.setReadOnly(true);
		C_num5.setName("hr_firstname_en");
		form.add(C_num5, td);
		
		form.add(new Label("lastname:"), td);
		TextField<String> C_num6 = new TextField<String>();
		C_num6.setReadOnly(true);
		C_num6.setName("hr_lastname_en");
		form.add(C_num6, td);
		
		form.add(new Label("城/乡:"), td);
		TextField<String> C_numcx = new TextField<String>();
		C_numcx.setReadOnly(true);
		C_numcx.setName("hr_City_Township");
		form.add(C_numcx, td);
		
		form.add(new Label("别名:"), td);
		TextField<String> C_num8 = new TextField<String>();
		C_num8.setReadOnly(true);
		C_num8.setName("hr_name_Alias");
		form.add(C_num8, td);
		
		form.inited();

		return form;
	};
	
	BaseStore<BusiObject> addrstore = null;
	BaseStore<BusiObject> getStore() {
		if (addrstore == null) {
			createStore();
		}
		return addrstore;
	}
	BaseStore<BusiObject> createStore() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("bcode");
		type.getField("bcode").setType(String.class);
		type.addField("addrtype");
		type.getField("addrtype").setType(String.class);
		type.addField("addr");
		type.getField("addr").setType(String.class);
		StoreInfo info = new StoreInfo();
		info.setTablename("bcodeaddr");
		info.setKeyname(new String[] { "icode" });
		info
				.setSql("select icode,bcode,addrtype,addr from bcodeaddr where bcode='{bcode}'");
		info.setParent(mainstore);// 关联主表
		info.setLinkparentcolumns(new String[] { "bcode" }); // 关联主表字段
		info.setLinkparent_chile_columns(new String[] { "bcode" });// 关联主表字段
		addrstore = new BaseStore<BusiObject>(type, info);
		return addrstore;
	}

	BaseGridPanel gridpanel = null;
	BaseGridPanel createGrid() {
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		BaseComboBoxX bc3 = new BaseComboBoxX("name","dictionary", "where type='hr_addrtype'");
		
		ColumnConfig C3 = new ColumnConfig("addrtype", "类型", 100);
		columns.add(C3);
		ColumnConfig C4 = new ColumnConfig("addr", "内容", 200);
		columns.add(C4);

		ColumnModel cm = new ColumnModel(columns);
		gridpanel = new BaseGridPanel(getStore(), cm);
		gridpanel.getBg().setHeight(130);
		gridpanel.getBg().setBorders(false);
		return gridpanel;
	}
	/**********/
	BaseStore<BusiObject> idcardstore = null;
	BaseStore<BusiObject> get_idcard_Store() {
		if (idcardstore == null) {
			create_idcard_Store();
		}
		return idcardstore;
	}
	BaseStore<BusiObject> create_idcard_Store() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("bcode");
		type.getField("bcode").setType(String.class);
		type.addField("type");
		type.getField("type").setType(String.class);
		type.addField("idNo");
		type.getField("idNo").setType(String.class);
		type.addField("addr");
		type.getField("addr").setType(String.class);
		type.addField("availableDate");
		type.getField("availableDate").setType(Date.class);
		type.addField("passAvailableDate");
		type.getField("passAvailableDate").setType(Date.class);
		type.addField("issue");
		type.getField("issue").setType(String.class);
		
		StoreInfo info = new StoreInfo();
		info.setTablename("hr_idCard");
		info.setKeyname(new String[] { "icode" });
		info
				.setSql("select * from hr_idCard where bcode='{bcode}'");
		info.setParent(mainstore);// 关联主表
		info.setLinkparentcolumns(new String[] { "bcode" }); // 关联主表字段
		info.setLinkparent_chile_columns(new String[] { "bcode" });// 关联主表字段
		idcardstore = new BaseStore<BusiObject>(type, info);
		return idcardstore;
	}
	BaseGridPanel cardgridpanel = null;
	BaseGridPanel create_card_Grid() {
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		
		BaseComboBoxX bc1 = new BaseComboBoxX("name","dictionary", "where type='hr_cardtype'");
		ColumnConfig C1 = new ColumnConfig("type", "证件类型", 80);
		columns.add(C1);

		ColumnConfig C2 = new ColumnConfig("idNo", "证件号", 120);
		columns.add(C2);
		
		ColumnConfig C3 = new ColumnConfig("addr", "地址", 200);
		columns.add(C3);
		
		ColumnConfig C4 = new ColumnConfig("availableDate", "有效日期", 85);
		DateField dateField4 = new DateField();  
	    dateField4.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));  
	    C4.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		columns.add(C4);
		
		ColumnConfig C5 = new ColumnConfig("passAvailableDate", "签证有效期", 85);
		DateField dateField5 = new DateField();  
	    dateField5.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));  
	    C5.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		columns.add(C5);
		
		ColumnConfig C6 = new ColumnConfig("issue", "签发机关", 120);
		columns.add(C6);

		ColumnModel cm = new ColumnModel(columns);
		cardgridpanel = new BaseGridPanel(get_idcard_Store(), cm);
		cardgridpanel.getBg().setHeight(130);
		cardgridpanel.getBg().setBorders(false);
		return cardgridpanel;
	}
	
/*******/
	
	BaseStore<BusiObject> imagestore = null;
	BaseStore<BusiObject> getImageStore(){
	if(imagestore==null) 
	{
		createImageStore();
	}
	return imagestore;
	}
	BaseStore<BusiObject> createImageStore(){
	ModelType type = new ModelType();
	type.setRoot("records");
	type.setRecordName("record");
	type.setTotalName("totle");
	type.addField("icode");
	type.getField("icode").setType(Long.class);
	type.addField("bcode");
	type.getField("bcode").setType(String.class);
	type.addField("bcodeimagepath");
	type.getField("bcodeimagepath").setType(String.class);
	StoreInfo info = new StoreInfo();
	info.setTablename("bcode_images");
	info.setKeyname(new String[] { "icode"});
	info.setSql("select * from bcode_images where bcode='{bcode}'");
	info.setParent(mainstore);// 关联主表
	info.setLinkparentcolumns(new String[] { "bcode" }); // 关联主表字段
	info.setLinkparent_chile_columns(new String[] { "bcode" });// 关联主表字段
	imagestore = new BaseStore<BusiObject>(type, info);
	 return imagestore;}
	
	
	public void addReFreshStore(BaseStore bs)
	{
		refresh_list.add(bs);
	}
	/*
	 * 人员图片
	 */
	ListView<BusiObject> view=null;
	
	ContentPanel CreateView() {
		final ContentPanel panel = new ContentPanel();
		panel.setFrame(true);
		panel.setId("images-view");
		panel.setHeaderVisible(false);
		panel.setWidth(180);

		// panel.setAutoHeight(true);
		panel.setHeight(165);
		panel.setBodyBorder(false);

		view = new ListView<BusiObject>() {
			@Override
			protected BusiObject prepareData(BusiObject model) {
			//	String s = model.get("b2cgcode");
				//model.set("shortName", Format.ellipse(s, 15));
		
				return model;
			}

		};

		view.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);  
		view.setTemplate(getTemplate());
		view.setStore(getImageStore());
		view.setHeight(165);
		view.setItemSelector("div.thumb-wrap");
		view.getSelectionModel().addListener(Events.SelectionChange,
				new Listener<SelectionChangedEvent<BusiObject>>() {

					public void handleEvent(SelectionChangedEvent<BusiObject> be) {
						panel
								.setHeading("产品图片("
										+ be.getSelection().size()
										+ " 个产品被选中)");
					
					}

				});
		panel.add(view);
		return panel;
	}
	private native String getTemplate() /*-{

	
	return ['<tpl  for=".">', 
    '<div class="thumb-wrap" id="{name}" style="border: 1px solid white;text-align:center;">', 
    '<div class="thumb" style="text-align:center;" ><img style="width:100px;height:133px;border:5px double #eee;margin: 3px 2px 2px 3px" src="{bcodeimagepath}" title="{name}"></div>', 
    '</div>', 
    '</tpl>',
    '<div class="x-clear"></div>'].join(""); 
}-*/;
	@Override
	public boolean isopen() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean open() {
		// TODO Auto-generated method stub
		return false;
	}
	public void set_hr_bcode() {
		hr_bcode=C_num2.getRawValue();
		GWT.log("fuck:"+hr_bcode);
	}
	public String get_hr_bcode() {
		return hr_bcode;
	}

}
